<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <title>样式绑定</title>
    <style>
        .basic{
            width: 200px;
            height: 100px;
            color: #333;
            text-align: center;
        }
        .normal{
            background-color: aqua;
        }
        .happy{
            background-color: yellowgreen;
        }
        .sad{
            background-color: tomato;
        }
        .ring{
            border-radius: 50%;
        }
        .squer{
            border: 2px solid red;
        }
        .bring{
            font-size: large;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div id="root">
        <!-- 绑定class样式--字符串写法，适用于样式的类名不确定，需要动态指定 -->
        <div class="basic" :class='mood' @click="changeMood">{{name}}</div>
        <br><br>
        <!-- 绑定class样式--数组写法，适用于样式的个数、名字不确定，需要动态指定 -->
        <div class="basic" :class='classArr'>{{name}}</div>
        <br><br>
        <!-- 绑定class样式--数组写法，适用于样式的个数、名字确定，但要动态决定是否使用 -->
        <div class="basic" :class='classObj'>{{name}}</div>
    </div>
    <script>
        new Vue({
            el:"#root",
            data:{
                name:"lss",
                mood:"normal",
                classArr:['ring','squer','bring'],
                classObj:{
                    ring:false,
                    squer:false
                }
            },

            methods: {
                changeMood(){
                    const arr = ['happy','sad','normal']
                    const index = Math.floor(Math.random()*3)
                    this.mood = arr[index]
                }
            },
        })
    </script>
</body>
</html>